package jmine.tec.rpc.server.representation.representers.collections;

import java.util.Set;

import jmine.tec.rpc.server.representation.RepresentationContext;
import jmine.tec.rpc.server.representation.representers.AbstractRepresenter;
import jmine.tec.utils.collection.IdentityHashSet;

/**
 * Representador de conjuntos.
 * 
 * @author lundberg
 */
public class SetRepresenter extends AbstractRepresenter<Set, SetRepresenterBean> {

    /**
     * Construtor
     */
    public SetRepresenter() {
        super(Set.class, SetRepresenterBean.class);
    }

    /**
     * {@inheritDoc}
     */
    public Set represent(RepresentationContext context, SetRepresenterBean object) {
        Set<Object> representation = new IdentityHashSet<Object>(object.getObjects().size());
        context.register(object, representation);
        for (Object represented : object.getObjects()) {
            representation.add(context.representObject(object.getRepresentationClass(), represented));
        }
        return representation;
    }
}
